<?php

class Application_Model_User extends Zend_Db_Table_Abstract
{
    protected $_name = 'tabel_user';
    
    public function selectUser($username)
    {
        $select = $this->select()->where('username = ? ', $username);
        $result = $this->fetchAll($select);
        
        if($result) {
            return $result->toArray ();
        
            echo 'Benar';
        } else {
            return false;
        }
    }
    
    public function userBaru($data)
    {
        $this->insert($data);
    }
    
    public function getAllData()
    {
        $select = $this->select();
        $select->setIntegrityCheck(false);
        $select->from($this->_name);
        
        $select->joinLeft('tabel_pegawai', 'tabel_user.id_pegawai = tabel_pegawai.id_pegawai', array('nama_pegawai' => 'nama_pegawai','nik' => 'nik'));
    
        $result = $this->fetchAll($select);
        
        return $result->toArray();
    }
    
    public function getDataById($id)
    {
        $select = $this->select();
        $select->setIntegrityCheck(false)
               ->from($this->_name, 'tabel_pegawai.nama_pegawai')
               ->where('id_user = ?', $id)
               ->joinLeft('tabel_pegawai', 'tabel_pegawai.id_pegawai = tabel_user.id_pegawai');
        
        $result = $this->fetchRow($select);
        
        return $result->toArray();
    }
    
    public function countData()
    {
        $select = $this->select();
        $select->setIntegrityCheck(false);
        $select->from($this->_name);
        
        $select->joinLeft('tabel_pegawai', 'tabel_user.id_pegawai = tabel_pegawai.id_pegawai', array('nama_pegawai' => 'nama_pegawai','nik' => 'nik'));
    
        $result = $this->fetchAll($select);
        
        return $result->count();
    }

}

